//
//  GoodsViewController.m
//  Mahjong
//
//  Created by KING on 16/9/11.
//  Copyright © 2016年 swift. All rights reserved.
//

#import "GoodsViewController.h"
#import "MoreSelectView.h"
#import "Header.h"
#import "GoodsTableViewCell.h"
@interface GoodsViewController ()
<UITableViewDelegate,UITableViewDataSource,selectDelegate>
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) MoreSelectView *selectView;
@property (nonatomic, assign) NSInteger did;
@property (nonatomic, retain) UIButton *brandButton;
@property (nonatomic, retain) UIButton *itemButton;
@end

@implementation GoodsViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.navigationBar.translucent = NO;
    // Do any additional setup after loading the view.
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, SCREENH_HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.myTableView registerNib:[UINib  nibWithNibName:@"GoodsTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    self.did = 0;
    [self createButton];
}
-(void)createButton{
    //品牌
    self.brandButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.brandButton.frame = CGRectMake(0, 0, SCREEN_WIDTH / 2.0, 50);
    [self.brandButton setTitle:@"出售中(30)" forState:UIControlStateNormal];
    [self.brandButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:self.brandButton];
    [self.brandButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //宝贝
    self.itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.itemButton.frame = CGRectMake(SCREEN_WIDTH / 2.0, 0, SCREEN_WIDTH / 2.0, 50);
    [self.itemButton setTitle:@"仓库中(30)" forState:UIControlStateNormal];
    [self.itemButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //    self.itemButton.titleLabel.font = [UIFont systemFontOfSize:0.037*SCREEN_WIDTH];
    [self.view addSubview:self.itemButton];
    [self.itemButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonAction:(UIButton *)btn{
    if (btn == self.brandButton) {
        [self.brandButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [self.itemButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        self.did =0;
        [self.myTableView reloadData];
    } else {
        [self.brandButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.itemButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        self.did = 1;
        [self.myTableView reloadData];

    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GoodsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (self.did == 0) {
        [cell.addButton setTitle:@"下架" forState:UIControlStateNormal];
    }
    if (self.did == 1) {
        [cell.addButton setTitle:@"上架" forState:UIControlStateNormal];
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
